﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
///Exam 的摘要说明
/// </summary>
public class Exam
{
    public Exam()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    /// <summary>
    /// 得到可以报名的考试
    /// </summary>
    /// <returns>返回DataTable对象</returns>
    public static DataTable GetExamDisplayNameByTime()
    {
        /*string cmdText = "Select ExamDisplayName,ExamUrl,a.TypeID,ExamYear,ExamNumber from Exam_Time a,Exam_Type b
         * where GETDATE()>=a.ExamBegin and GETDATE()<=a.ExamEnd and a.TypeID=b.TypeID order by TimeID asc";*/
        string cmdText = @"select * from ExamTime
    where GETDATE()>= DATEADD(day,-30,ApplyBeginTime) and GETDATE()< DATEADD(day,1,ApplyEndTime)
        order by TimeID asc";
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, null);
    }

    /// <summary>
    /// 通过考试编号获取考试等级名称
    /// </summary>
    /// <param name="EmID">考试编号，例如四级考试就有例如2015004编号</param>
    /// <returns>返回datatable对象</returns>
    public static DataTable getRankNameByEmID(string EmID)
    {
        string cmdText = "select DISTINCT EmID, EmRankName from ExamRank where EmID=@EmID";
        SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@EmID",SqlDbType.VarChar,10)};
        parms[0].Value = EmID.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text,cmdText,parms);
    }
    

    /// <summary>
    /// 通过身份证号得到报名信息
    /// </summary>
    /// <param name="studIdCard">身份证号码</param>
    /// <param name="emId">考试编号</param>
    /// <param name="emYear">考试年份</param>
    /// <param name="emNum">考试次数</param>
    /// <returns>返回一个datatable对象</returns>
    //public static DataTable getBMInfoByStudIdCard(string studIdCard, string emId, string emYear, string emNum)
    public static DataTable getBMInfoByStudIdCard(string studIdCard, string emId,string emYear,string emNum)
    {
        string cmdText = "Select * from ApplyInfo where StudIdcard=@StudIdcard and EmID=@EmID and EmYear=@EmYear and EmNum=@EmNum";
        SqlParameter[] parms = new SqlParameter[]{													   
				new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),
				new SqlParameter("@EmID",SqlDbType.VarChar,10),
                new SqlParameter("@EmYear",SqlDbType.Char,4),
                new SqlParameter("@EmNum",SqlDbType.TinyInt),
			};
        parms[0].Value = studIdCard.Trim();
        parms[1].Value = emId.Trim();
        parms[2].Value = emYear.Trim();
        parms[3].Value = emNum.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 插入报名信息
    /// </summary>
    /// <param name="studIdcard">身份证号</param>
    /// <param name="emId">考试编号</param>
    /// <param name="emRankName">考试等级名称</param>
    /// <returns>返回datatable对象</returns>
    public static bool BMInfo_Insert(string studIdcard, string emId, string emRankName)
    {
        try
        {
            string cmdText = @"insert into ApplyInfo                    (StudIdcard,StudName,StudID,StudTel,StudSex,StudDeptName,StudClassName,StudFrom,StudPic,EmID,EmRankName,EmAllName,
                            EmYear,EmNum,EmCost,ApplyState,ApplyCtTime)
            select distinct StudIdcard,StudName,StudID,StudTel,StudSex,StudDeptName,StudClassName,StudFrom,StudPic,ExamRank.EmID,EmRankName,EmAllName,EmYear,EmNum,EmCost,0,GETDATE()
                 from StudentInfo,ExamRank,ExamTime where StudIdcard=@StudIdcard and EmRankName=@EmRankName and
                    ExamRank.EmID=ExamTime.EmID and ExamRank.EmID=@EmID";
            SqlParameter[] parms = new SqlParameter[]{			
			            new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),								   
					    new SqlParameter("@EmID",SqlDbType.VarChar,10),	
                        new SqlParameter("@EmRankName",SqlDbType.NVarChar,20)
			};
            parms[0].Value = studIdcard.Trim();
            parms[1].Value = emId.Trim();
            parms[2].Value = emRankName.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;

        }
    }
    /// <summary>
    /// 更新报名信息
    /// </summary>
    /// <param name="studIdcard">身份证号</param>
    /// <param name="emId">考试编号</param>
    /// <param name="emYear">考试年份</param>
    /// <param name="emNum">考试次数</param>
    /// <returns>返回一个boolean</returns>
    public static bool BMInfo_Update(string studIdcard, string emId, string emYear, string emNum, string emRankName)
    {
        try
        {
            string cmdText = @"update ApplyInfo set EmID=@EmID,EmRankName=@EmRankName
                                where StudIdcard=@StudIdcard  and EmYear=@EmYear and EmNum=@EmNum";
            SqlParameter[] parms = new SqlParameter[]{			
			        new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),
                    new SqlParameter("@EmYear",SqlDbType.Char,4),
                    new SqlParameter("@EmNum",SqlDbType.TinyInt),
                    new SqlParameter("@EmID",SqlDbType.VarChar,10),
                    new SqlParameter("@EmRankName",SqlDbType.NVarChar,20)
			};
            parms[0].Value = studIdcard.Trim();
            parms[1].Value = emYear.Trim();
            parms[2].Value = emNum.Trim();
            parms[3].Value = emId.Trim();
            parms[4].Value = emRankName.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.ToString());

        }
    }

    /// <summary>
    /// 保存报名信息
    /// </summary>
    /// <param name="studIdcard">身份证号</param>
    /// <param name="emYear">考试年份</param>
    /// <param name="emNum">考试次数</param>
    /// <param name="emId">考试编号</param>
    /// <param name="emRankName">考试等级名称</param>
    /// <returns>返回一个保存的boolean</returns>
    public static bool BMInfo_Save(string studIdcard, string emYear, string emNum, string emId,string emRankName)
    {
        try
        {
            int count = getBMInfoByStudIdCard(studIdcard,emId,emYear,emNum).Rows.Count;
            if (count == 0)
            {
                // BMInfo_Insert(sfzh, typeID, levelID_1, levelID_2);
                /*添加信息说明：不存在信息就进行保存--zhenglongfan*/
                if (BMInfo_Insert(studIdcard, emId, emRankName))
                {
                    return true;
                }
                else
                {
                    return false;
                }
                
            }
            else if (count == 1)
            {
                // BMInfo_Update(sfzh, typeID, examyear, examnumber, levelID_1, levelName_1, levelID_2, levelName_2);
                /*添加信息说明：存在信息进行更新--zhenglonfan*/
                if (BMInfo_Update(studIdcard, emId, emYear, emNum, emRankName))
                {
                    return true;
                }
                else
                {
                    return false;
                }
                
            }
            return false;
        }
        catch
        {
            return false;
        }

    }
    /// <summary>
    /// 更新报名信息
    /// </summary>
    /// <param name="studIdcard">学生身份证号</param>
    /// <param name="emType">考试类型</param>
    /// <param name="emYear">考试年份</param>
    /// <param name="emNum">考试次数</param>
    /// <param name="applyState">报名状态</param>
    public static bool UpdateBMState(string studIdcard, string emType, string emYear, string emNum, string applyState)
    {
        try
        {
            string cmdText = "update ApplyInfo set ApplyState=@ApplyState where StudIdcard=@StudIdcard and EmType=@EmType and EmYear=@EmYear and EmNum=@EmNum";
            SqlParameter[] parms = new SqlParameter[]{			
			    new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),	
			    new SqlParameter("@EmType",SqlDbType.TinyInt),	
                new SqlParameter("@EmYear",SqlDbType.Char,4),
                new SqlParameter("@EmNum",SqlDbType.TinyInt),
                new SqlParameter("@ApplyState",SqlDbType.Int),
			};
            parms[0].Value = studIdcard.Trim();
            parms[1].Value = emType.Trim();
            parms[2].Value = emYear.Trim();
            parms[3].Value = emNum.Trim();
            parms[4].Value = applyState.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;

        }
    }
    public static bool updateOrderIDInApplyInfo(string applyId, string orderId)
    {
        try
        {
            string cmdText = "update ApplyInfo set OrderID=@orderId where ApplyID=@applyId";
            SqlParameter[] parms = new SqlParameter[]{
                new SqlParameter("@orderId",SqlDbType.Int),
                new SqlParameter("@applyId",SqlDbType.Int)
            };
            parms[0].Value = orderId.Trim();
            parms[1].Value = applyId.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
    /// <summary>
    /// 创建订单
    /// </summary>
    /// <param name="studIdcard">学生身份证号</param>
    /// <param name="emRankName">考试等级</param>
    /// <param name="emYear">考试年份</param>
    /// <param name="emNum">考试次数</param>
    /// <param name="emId">考试编号</param>
    /// <returns></returns>
    public static int CreateOrderInfo(string studIdcard, string emRankName, string emYear, string emNum , string emId)
    {
        try
        {
            //string cmdText = "BM_CreateOrderInfo(@SFZH,@TypeID,@ExamYear,@ExamNumber)";
            SqlParameter[] parms = new SqlParameter[]{			
			    new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),
				new SqlParameter("@EmRankName",SqlDbType.NVarChar,20),	
                new SqlParameter("@EmYear",SqlDbType.Char,4),
                new SqlParameter("@EmNum",SqlDbType.TinyInt),
                new SqlParameter("@EmID",SqlDbType.VarChar,10),
                new SqlParameter("@OrderID",SqlDbType.Int)
			};
            parms[0].Value = studIdcard.Trim();
            parms[1].Value = emRankName.Trim();
            parms[2].Value = emYear.Trim();
            parms[3].Value = emNum.Trim();
            parms[4].Value = emId.Trim();
            parms[5].Direction = ParameterDirection.Output;
            Dbase.ExecuteNonQuery(CommandType.StoredProcedure, "BM_CreateOrder", parms);
            
            return (int)parms[5].Value;
        }
        catch (Exception ex)
        {
            return 0;

        }
    }

    public static bool upAllData(string orderId)
    {
        try
        {
            SqlParameter[] parms = new SqlParameter[]{
                new SqlParameter("@orderId",SqlDbType.Int)
            };
            parms[0].Value = orderId.Trim();
            Dbase.ExecuteNonQuery(CommandType.StoredProcedure, "UpDataAll", parms);
            return true;
        }
        catch
        {
            return false;
        }
    }

    /// <summary>
    /// 通过订单号获取订单信息
    /// </summary>
    /// <param name="orderid">订单号</param>
    /// <returns>返回一个包含定的那信息datatable对象</returns>
    public static DataTable getOrderInfoByOrderID(string orderid)
    {
        //string cmdText = "Select * from Exam_OrderInfo where OrderID=@OrderID";
        string cmdText = "select * from OrderInfo where OrderID=@OrderID";
        SqlParameter[] parms = new SqlParameter[]{													   
			 new SqlParameter("@OrderID",SqlDbType.Int),
		};
        parms[0].Value = orderid.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 更新订单信息
    /// </summary>
    /// <param name="orderId">订单号</param>
    /// <param name="state">状态</param>
    public static bool Update_OrderState(string orderId,string state)
    {
        try
        {
            string cmdText = "update OrderInfo set OrderState=@OrderState where OrderID=@OrderID";
            SqlParameter[] parms = new SqlParameter[]{			
			    new SqlParameter("@OrderID",SqlDbType.Int),
                new SqlParameter("@OrderState",SqlDbType.TinyInt)
			};
            parms[0].Value = orderId.Trim();
            parms[1].Value = state.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;

        }
    }
    /// <summary>
    /// 通过订单号获取订单状态
    /// </summary>
    /// <param name="orderId">订单号</param>
    /// <returns>返回订单状态</returns>
    public static int get_OrderState(string orderId)
    {
        try
        {
            //string cmdText = "select OrderState from Exam_OrderInfo where OrderID=@OrderID";
            string cmdText = "select OrderState from OrderInfo where OrderID=@OrderID";
            SqlParameter[] parms = new SqlParameter[]{			
		        new SqlParameter("@OrderID",SqlDbType.Int),
			};
            parms[0].Value = orderId.Trim();
            object o =  Dbase.ExecuteScalar(CommandType.Text, cmdText, parms);
            int i=-1;
            if (int.TryParse(o.ToString(), out i))
            {
                return i;
            }
            else
            {
                return -1;
            }
            
        }
        catch (Exception ex)
        {
            throw new Exception(ex.ToString());
        }
    }
    
    //public static DataTable GetHistoryScoreBySFZH(string applyId)
    /// <summary>
    /// 通过报名号获取历史成绩
    /// </summary>
    /// <param name="applyId"></param>
    /// <returns></returns>
    public static DataTable getHistoryScoreByApplyId(string applyId)
    {
        //string cmdText = "Select * from Exam_HistoryScore where SFZH=@SFZH";
        string cmdText = "select * from HistoryScore where ApplyID=@ApplyID";
        SqlParameter[] parms = new SqlParameter[]{	
			new SqlParameter("@ApplyID",SqlDbType.VarChar,20)
		};
        parms[0].Value = applyId.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 更新报名完成时间
    /// </summary>
    /// <param name="studIdcard"></param>
    /// <param name="emRankName"></param>
    /// <param name="emYear"></param>
    /// <param name="emNum"></param>
    /// <param name="applyFhTime"></param>
    public static bool UpdateBMCompleteTime(string studIdcard, string emId,string emYear,string emNum)
    {
        try
        {
            string cmdText = "update ApplyInfo set ApplyFhTime=GETDATE() where StudIdcard=@StudIdcard and EmID=@emId and EmYear=@emYear and EmNum=@emNum";
            SqlParameter[] parms = new SqlParameter[]{			
			    new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),								   
			    new SqlParameter("@emId",SqlDbType.VarChar,20),
                new SqlParameter("@emYear",SqlDbType.Char,4),
                new SqlParameter("@emNum",SqlDbType.TinyInt)
			};
            parms[0].Value = studIdcard.Trim();
            parms[1].Value = emId.Trim();
            parms[2].Value = emYear.Trim();
            parms[3].Value = emNum.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true; 
        }
        catch (Exception ex)
        {
            return false;

        }
    }

    /// <summary>
    /// 号更新订单完成时间
    /// </summary>
    /// <param name="orderId">订单号</param>
    /// <param name="orderFhTime">订单完成时间</param>
    public static bool UpdateOrderEndDate(string orderId)
    {
        try
        {
            string cmdText = "update OrderInfo set OrderFhTime=GETDATE() where OrderID=@OrderID";
            SqlParameter[] parms = new SqlParameter[]{			
			    new SqlParameter("@OrderID",SqlDbType.Int)
			};
            parms[0].Value = orderId.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;

        }
    }
    /// <summary>
    /// 更新报名报名状态
    /// </summary>
    /// <param name="applyId">报名号</param>
    /// <param name="applyState">报名状态</param>
    /// <returns>是否更新成功</returns>
    public static bool updateApplyState(string applyId,string applyState)
    {
        try
        {
            string cmdText = "update ApplyInfo set ApplyState=@applyState where ApplyID=@applyID";
            SqlParameter[] parms = new SqlParameter[]{
                new SqlParameter("@applyId",SqlDbType.VarChar,18),
                new SqlParameter("@applyState",SqlDbType.TinyInt)
            };
            parms[0].Value = applyId.Trim();
            parms[1].Value = applyState.Trim();
            Dbase.ExecuteNonQuery(CommandType.Text, cmdText, parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
    /// <summary>
    /// 重新开始报名
    /// </summary>
    /// <param name="studIdcard">学生身份证号</param>
    /// <param name="emId">考试id</param>
    /// <param name="emYear">考试年份</param>
    /// <param name="emNum">考试次数</param>
    public static bool BMRestart(string studIdcard, string emId, string emYear, string emNum)
    {
        try
        {
            SqlParameter[] parms = new SqlParameter[]{			
			    new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),
			    new SqlParameter("@EmID",SqlDbType.VarChar,10),	
                new SqlParameter("@EmYear",SqlDbType.Char,4),
                new SqlParameter("@EmNum",SqlDbType.TinyInt),
			};
            parms[0].Value = studIdcard.Trim();
            parms[1].Value = emId.Trim();
            parms[2].Value = emYear.Trim();
            parms[3].Value = emNum.Trim();
            Dbase.ExecuteNonQuery(CommandType.StoredProcedure, "BM_Restart", parms);
            return true;
        }
        catch (Exception ex)
        {
            return false;

        }
    }
    /// <summary>
    /// 通过考试编号得到考试时间信息
    /// </summary>
    /// <param name="emId"></param>
    /// <returns></returns>
    public static DataTable getEmTimeByEmId(string emId)
    {
        string cmdText = "select * from ExamTime where EmID=@EmId";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@EmId",SqlDbType.Int) 
        };
        parms[0].Value = emId.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text,cmdText,parms);

    }
    /// <summary>
    /// 通过身份证号得到学生信息
    /// </summary>
    /// <param name="studIdCard"></param>
    /// <returns></returns>
    public static DataTable getStudInfoByIdCard(string studIdCard)
    {
        string cmdText = "select * from StudentInfo where StudIdcard=@StudIdcard";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@StudIdcard",SqlDbType.VarChar,18) 
        };
        parms[0].Value = studIdCard.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 通过身份证号和考试编号得到订单信息
    /// </summary>
    /// <param name="studIdCard">身份证号</param>
    /// <param name="emId">考试编号</param>
    /// <returns></returns>
    public static DataTable getOrderInfoByMsg(string studIdCard, string emId)
    {
        string cmdText = "select * from OrderInfo where StudIdcard=@StudIdcard and EmID=@EmId";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@StudIdcard",SqlDbType.VarChar,18),
            new SqlParameter("@EmId",SqlDbType.VarChar,10)
        };
        parms[0].Value = studIdCard.Trim();
        parms[1].Value = emId.Trim();
        
        return (DataTable)Dbase.GetDataTable(CommandType.Text,cmdText,parms);
    }
    /// <summary>
    /// 通过身份证号得到所有报名的信息
    /// </summary>
    /// <param name="IdCard">身份证号</param>
    /// <returns>含有同一个人的所有报名信息</returns>
    public static DataTable getApplyInfosByIdCard(string IdCard)
    {
        string cmdText = "select * from ApplyInfo where StudIdcard=@StudIdCard";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@StudIdCard", SqlDbType.VarChar, 18)
        };
        parms[0].Value = IdCard.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 得到用户信息
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="userId"></param>
    /// <returns></returns>
    public static DataTable getUserInfoByLoginMsg(string userName, string userId)
    {
        string cmdText = "select * from UserInfo where UserName=@userName and StudIdcard=@StudIdcard";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@userName",SqlDbType.NVarChar,20),
            new SqlParameter("@StudIdcard",SqlDbType.VarChar,20)
        };
        parms[0].Value = userName.Trim();
        parms[1].Value = userId.Trim();

        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
   
    /// <summary>
    /// 得到单个用户所有的订单信息
    /// </summary>
    /// <param name="idCard"></param>
    /// <returns></returns>
    public static DataTable getOrderInfosByIdCard(string idCard)
    {
        string cmdText = @"select ApplyID,OrderInfo.OrderID,OrderInfo.EmAllName,OrderInfo.EmCost,OrderCtTime,OrderFhTime,OrderState,EmRankName
                            from  OrderInfo,ApplyInfo 
                            where OrderInfo.StudIdcard=@idCard
		                        and ApplyInfo.StudIdcard=@idCard and ApplyInfo.OrderID=OrderInfo.OrderID";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@idCard",SqlDbType.VarChar,18)
        };
        parms[0].Value = idCard.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 得到同一个用户的历史成绩信息
    /// </summary>
    /// <param name="idCard"></param>
    /// <returns></returns>
    public static DataTable getHistoryScoreByIdCard(string idCard)
    {
        string cmdText = @"select * from HistoryScore,ApplyInfo where HistoryScore.ApplyID=ApplyInfo.ApplyID and StudIdcard=@idCard order by ScoreGetTime asc";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@idCard",SqlDbType.VarChar,18)
        };
        parms[0].Value = idCard.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    public static DataTable getApplyInfoByOrderId(string orderId)
    {
        string cmdText = "select * from ApplyInfo where OrderID=@orderId";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@orderId",SqlDbType.Int)
        };
        parms[0].Value = orderId.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    public static DataTable getApplyInfoByApplyId(string applyId)
    {
        string cmdText = "select * from ApplyInfo where ApplyID=@applyId";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@applyId",SqlDbType.Int)
        };
        parms[0].Value = applyId.Trim();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
    }
    /// <summary>
    /// 得到所有报名信息
    /// </summary>
    /// <returns></returns>
    public static DataTable getAllApplyInfos()
    {
        string cmdText = "select * from ApplyInfo";
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, null);
    }
    /// <summary>
    /// 得到所有订单信息
    /// </summary>
    /// <returns></returns>
    public static DataTable getAllOrderInfos()
    {
        string cmdText = @"select ApplyID,OrderInfo.OrderID,OrderInfo.EmAllName,OrderInfo.EmCost,OrderCtTime,OrderFhTime,OrderState from               OrderInfo,ApplyInfo where  ApplyInfo.OrderID=OrderInfo.OrderID";
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, null);
    }

    public static DataTable GetOrderListByDays(int days)
    {
        string cmdText = @" select b.* from OrderInfo as a,ApplyInfo as b where a.OrderID = b.OrderID and OrderState>=5 and OrderState <= 6 and DATEDIFF(DAY,OrderCtTime,GETDATE()) < @Days ";
        SqlParameter[] parms = new SqlParameter[]{
            new SqlParameter("@Days",SqlDbType.Int)
        };
        parms[0].Value = days.ToString();
        return (DataTable)Dbase.GetDataTable(CommandType.Text, cmdText, parms);
 
    }
}



